﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace EBookStore.UnitTests
{
    [TestFixture]
    [Category("Managers")]
    class Test_OrdersManager
    {
         [Test]
         public void TestEquality()
         {
             Management.OrdersManager o1 = Management.OrdersManager.Instance;
             Management.OrdersManager o2 = Management.OrdersManager.Instance;

             Assert.AreEqual(o1, o2);
         }


         [Test]
         public void TestAddOrder()
         {
             Management.OrdersManager o1 = Management.OrdersManager.Instance;
             Users.User user = new Users.Customer("a", "a", ",a");

             Management.PublisherManager.Instance.AddPublishers(ObjectsGenerator.GeneratePublishers(100));

             Books.Catalog.Instance.AddBooks(ObjectsGenerator.GenerateBooks(100,
                 Management.PublisherManager.Instance.Publishers.ToArray()));


             Books.Book[] books = Books.Catalog.Instance.ToArray();
             List<Orders.SingleBookOrder> so =  new List<Orders.SingleBookOrder>();
             so.Add(new Orders.SingleBookOrder(books[0], 20));
             so.Add(new Orders.SingleBookOrder(books[1], 2));
             so.Add(new Orders.SingleBookOrder(books[2], 3));
             so.Add(new Orders.SingleBookOrder(books[3], 4));


             Assert.That(
                () => o1.CreateOrder(user, Orders.eOrderVia.Email, null, so.ToArray()),
                    Throws.Exception.TypeOf<Exception>());
             
             Orders.Order order = o1.CreateOrder(
                 user,
                 Orders.eOrderVia.Email,
                 new Payments.CreditCardPayment("123", Payments.eCreditCard.AmericanExpress),
                 so.ToArray());

             Assert.AreNotEqual(null, order);

             Assert.Greater(o1.OrdersList.Count,0);


             Assert.AreEqual(Orders.eOrderStatus.Charged, order.Status);
             
         }

        



    }
}
